package nid.gallery 
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author Nidin P Vinayakan
	 */
	public class Thumb extends Sprite 
	{
		public var id:int;
		
		public function Thumb(data:XML=null) 
		{
			this.buttonMode = true;
			this.mouseChildren = false;
			loadThumb(data);
		}
		
		private function loadThumb(data:XML=null):void 
		{
			this.graphics.beginFill(0xcccccc,0.75);
			this.graphics.drawRect(0, 0, 60, 60);
			this.graphics.endFill();
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
			loader.load(new URLRequest(data.@thumb));
		}
		
		private function onComplete(e:Event):void 
		{
			var bmp:Bitmap = Bitmap(e.target.content);
			bmp.x = 5;
			bmp.y = 5;
			bmp.width = 50;
			bmp.height = 50;
			addChild(bmp);
		}
		
		private function onIOError(e:IOErrorEvent):void 
		{
			trace('io error');
		}
		
	}

}